<?php

namespace backend\models;

use backend\models\UserDecorate;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use yii\data\Sort;

/**
 * SysItemSearch represents the model behind the search form about `backend\models\SysItem`.
 */
class UserDecorateSearch extends UserDecorate
{
    /**
     * @inheritdoc
     */
		 public function rules()
		    {    	
		        return [
		            [['id','user_id'], 'integer'],
                    [['villiage_name','decorate_company','username','tel'],'string'],
		        ];
		    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $this->load($params);
		$query=UserDecorate::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
	        'pagination'=>['pageSize' => '10'],
        	'sort'=> [
        	    'defaultOrder' => [
        	        'id' => SORT_DESC
                ]
            ]
        ]);

        if (!$this->validate()) {
            return $dataProvider;
        }
	
        $query->andFilterWhere(['id' => $this->id,])
			->andFilterWhere(['user_id' => $this->user_id,])
            ->andFilterWhere(['like', 'villiage_name', $this->villiage_name])
            ->andFilterWhere(['like', 'decorate_company', $this->decorate_company])
            ->andFilterWhere(['like', 'username', $this->username])
            ->andFilterWhere(['like', 'tel', $this->tel])
        ;

       /*  $query->andFilterWhere(['like', 'afterservice_order.username', $this->username])
            ->andFilterWhere(['like', 'afterservice_order.phone', $this->phone])
            ->andFilterWhere(['like', 'afterservice_order.trade_no', $this->trade_no])
            ->andFilterWhere(['like', 'FROM_UNIXTIME(afterservice_order.createtime, "%Y-%m-%d")', $this->createtime])
           ; */
        return $dataProvider;
    }
    
}
